const animateQueue = []
export default function animate(el, style, transition) {
  transition = transitionStr(transition)
  animateQueue.push({
    el,
    style,
    transition
  })
  if(animateQueue.length === 1) {
    setTimeout(() => {
      queue(animateQueue)
    }, 0);
  }
}
function transitionStr(val) {
  switch(typeof val) {
    case 'string': 
      return val
    case 'number':
      return `all ${val}ms`
    case 'object':
      return `${val.property || 'all'} ${val.duration || new Error('必须指定过渡持续时长')}ms ${val.timingFunction || 'linear'} ${val.delay || 0}ms`
  }
}
function queue(queue) {
  var obj = queue.shift()
  obj.el.style.transition = obj.transition
  for(var item in obj.style) {
    obj.el.style[item] = obj.style[item]
  }
  if(queue.length !== 0) {
    setTimeout(() => {
      this.queue(queue)
    }, /\d+/.exec(transition(obj.transition)));
  }
}